﻿using System.Drawing;
using System.Windows.Forms;

namespace Multivee.UI
{
    public class ScreenViewController
    {
        public static void Display(ScreenViewConfiguration configuration)
        {
            for (int i = 0; i < Screen.AllScreens.Length; i++)
            {
                Screen screen = Screen.AllScreens[i];
                ScreenView view = new ScreenView(i == 0 ? Properties.Resources.Tile1 : Properties.Resources.Tile2);
                
                view.Location = screen.Bounds.Location;
                view.Show();
                System.Diagnostics.Debug.WriteLine("Screen {0} bounds: {1}", i + 1, screen.Bounds);
            }
        }

        public static Bitmap MakeMosaic(ScreenViewConfiguration configuration)
        {
            Bitmap tile = new Bitmap(configuration.Tile);
            Bitmap mosaic = new Bitmap(configuration.ScreenSize.Width, configuration.ScreenSize.Height);

            using (Graphics g = Graphics.FromImage(mosaic))
            {
                int y = 0;
                int x = 0;

                while (y < mosaic.Height)
                {
                    // Draw the specified section of the source bitmap to the new one
                    g.DrawImage(tile, x, y, tile.Width, tile.Height);

                    x += tile.Width + 6;
                    if(x >= mosaic.Width)
                    {
                        x = 0;
                        y += tile.Height;
                    }
                }
            }

            // Return the bitmap
            return mosaic;
        }
    }
}
